<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>10_组件基本使用</title>
    <script type="text/javascript" src="js/vue.js"></script>
</head>

<body>
    <div id="root">
        <hello></hello>
        <xuexiao></xuexiao>
        <hr>
        <xueshen></xueshen>
        <xueshen></xueshen>
    </div>
    <div id="root2">
        <hello></hello>
    </div>
    <script type="text/javascript">
        const school = Vue.extend({
            template: `<div><h2>{{schoolName}}</h2>
                <h2>{{schooladdress}}</h2>
                <button @click="showName">点我提示学校名</button>
                </div>`,
            data: function () {
                return {
                    schoolName: '清华大学',
                    schooladdress: '北京市海淀区'
                }
            },
            methods: {
                showName: function () {
                    alert(this.schoolName);
                }
            },
        });
        const student = Vue.extend({
            template: `<div><h2>{{studentName}}</h2><h2>{{age}}</h2></div>`,
            data: function () {
                return {
                    studentName: '张三',
                    age: 18
                }
            }
        });

        const hello = Vue.extend({
            template: `<div><h2>hello,{{name}}</h2></div>`,
            data: function () {
                return {
                    name: 'Tom'
                }
            }
        });

        Vue.component('hello', hello);

        new Vue({
            el: '#root',
            components: {
                xuexiao: school,
                xueshen: student
            },
        })

        new Vue({
            el: '#root2',
        })
    </script>
</body>

</html>